package templatex

import (
	"html/template"
	"strings"
)

// GetStringByFile 根据模板文件获取字符串
func GetStringByFile(data any, fileNames ...string) (string, error) {
	t, err := template.ParseFiles(fileNames...)
	if err != nil {
		return "", err
	}
	s := new(strings.Builder)
	err = t.Execute(s, data)
	if err != nil {
		return "", err
	}
	return s.String(), nil
}
